function getBrowserType() {
    var browserType = "";
    if(navigator.userAgent.indexOf("MSIE") != -1){
        browserType = "IE";
    }else if(navigator.userAgent.indexOf("Chrome") != -1){
        browserType = "Chrome";
    }else if(navigator.userAgent.indexOf("Firefox") != -1){
        browserType = "Firefox"
    }
    return browserType;
}

function informationxmlparse(xmlDom) {
    if(this.getBrowserType() == "IE"){//IE浏览器
        xmlDom = new ActiveXObject('Microsoft.XMLDOM');
        xmlDom.async = false;
        xmlDom.load(this.getXmlFile());
    }else{
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", xmlDom, false);
        xmlhttp.send(null);
        xmlDom = xmlhttp.responseXML;
    }
    // console.log(xmlDom);
    if(this.getBrowserType() == "IE"){

    }else{
        try{

            var algorithmInfo = new Object();
            algorithmInfo.name = xmlDom.getElementsByTagName("name")[0].textContent;
            console.log(algorithmInfo.name);
            algorithmInfo.algorithmType = xmlDom.getElementsByTagName("field")[0].textContent;
            algorithmInfo.algorithmFunction = xmlDom.getElementsByTagName("algorithmFunction")[0].textContent;
            algorithmInfo.version = xmlDom.getElementsByTagName("version")[0].textContent;
            algorithmInfo.companyName = xmlDom.getElementsByTagName("company")[0].textContent;
            algorithmInfo.introduction = xmlDom.getElementsByTagName("introduction")[0].textContent;
            algorithmInfo.platform = xmlDom.getElementsByTagName("platform")[0].textContent;
            algorithmInfo.postfix = xmlDom.getElementsByTagName("postfix")[0].textContent;
            algorithmInfo.isContainGpu = xmlDom.getElementsByTagName("gpu")[0].textContent;
            algorithmInfo.isUseMpi = xmlDom.getElementsByTagName("mpi")[0].textContent;
            if(xmlDom.getElementsByTagName("cpuNum").length>0){
                algorithmInfo.cpuNum = xmlDom.getElementsByTagName("cpuNum")[0].textContent;
            }else{
                algorithmInfo.cpuNum = 0;
            }
            algorithmInfo.isLeft = xmlDom.getElementsByTagName("isLeft")[0].textContent;

            var file = xmlDom.getElementsByTagName("file");
            var AlgorithmOutput = xmlDom.getElementsByTagName("AlgorithmOutput");
            var InputParam = xmlDom.getElementsByTagName("InputParam");
            var inputfiles = new Array();
            var AlgorithmOutputs = new Array();
            var AlgorithmParams = new Array();
            console.log(file.length);
            for(var i=0;i< file.length;i++){
                if(file[i].getElementsByTagName("suffix").length>0){
                    inputfiles.push({
                        inputName:file[i].getElementsByTagName("fileParam")[0].textContent,
                        type:file[i].getElementsByTagName("fileType")[0].textContent,
                        inputIntroduction:file[i].getElementsByTagName("fileIntroduction")[0].textContent,
                        suffix:file[i].getElementsByTagName("suffix")[0].textContent
                    })
                }else{
                    inputfiles.push({
                        inputName:file[i].getElementsByTagName("fileParam")[0].textContent,
                        type:file[i].getElementsByTagName("fileType")[0].textContent,
                        inputIntroduction:file[i].getElementsByTagName("fileIntroduction")[0].textContent,
                        suffix:""
                    })
                }

            }
            algorithmInfo.inputCount =inputfiles;

            for(var i=0;i< AlgorithmOutput.length;i++){
                if(AlgorithmOutput[i].getElementsByTagName("suffix").length>0){
                    AlgorithmOutputs.push({
                        outputName:AlgorithmOutput[i].getElementsByTagName("outputName")[0].textContent,
                        type:AlgorithmOutput[i].getElementsByTagName("outputType")[0].textContent,
                        outputIntroduction:AlgorithmOutput[i].getElementsByTagName("outputIntroduction")[0].textContent,
                        suffix:AlgorithmOutput[i].getElementsByTagName("suffix")[0].textContent
                    })
                }else{
                    AlgorithmOutputs.push({
                        outputName:AlgorithmOutput[i].getElementsByTagName("outputName")[0].textContent,
                        type:AlgorithmOutput[i].getElementsByTagName("outputType")[0].textContent,
                        outputIntroduction:AlgorithmOutput[i].getElementsByTagName("outputIntroduction")[0].textContent,
                        suffix:""
                    })
                }

            }
            algorithmInfo.outputCount = AlgorithmOutputs;

            for(var i=0;i< InputParam.length;i++){
                AlgorithmParams.push({
                    paramSymbol:InputParam[i].getElementsByTagName("param")[0].textContent,
                    paramType:InputParam[i].getElementsByTagName("paramType")[0].textContent,
                    paramIntroduction:InputParam[i].getElementsByTagName("paramIntroduction")[0].textContent,
                    paramDefaultValue:InputParam[i].getElementsByTagName("value")[0].textContent
                })
            }
            algorithmInfo.paramsCount = AlgorithmParams;
            var algorithmInfo_json = JSON.stringify(algorithmInfo);
            console.log(algorithmInfo_json);
            return algorithmInfo_json;
        }catch (e){
            layer.alert("算法组件文件格式有误，请重新上传！")
        }
    }
}
var xmlhttp = {
    algorithInfo:0
}
function algorithmupload(input) {
    var paramFlieresString=$("#paramxmlfile").val();
    var str = paramFlieresString.split("\\");
    var paramFlieres = str[str.length-1];
    if(paramFlieres!=""){
        $('#paramfileShow_div').html(paramFlieres);
        $("#paramfileShow_div").show();

    }else{
        $('#paramfileShow_div').html('您还没有输入任何东西');
        $("#paramfileShow_div").show();
    }
    var algo={
        algorithInfo:1
    };
    var file = input.files[0];
    filename = file.name.split(".")[0];
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload =function(e) {
        var data = e.target.result;
        console.log(data);
        algo.algorithInfo =informationxmlparse(data);
        xmlhttp.algorithInfo=algo.algorithInfo;
    }
}

function showDetail() {
    $.ajax({
        url:constUrl+"CompanyServlet",
        type:'post',
        data:{
            operateType:"showAll",
            onePageCount:"10",
            currentPage:"1"
        },
        dataType:'json',
        success: function(responseText) {
            var companyHtml ='';
            for(var i=0;i<responseText.datas.length;i++){
                companyHtml+='<option value="'+(responseText.datas[i].companyId)+'" >'+responseText.datas[i].companyName+'</option>'

            }
            $("#jsonInfo").attr("aString",companyHtml);
        },
        complete: function() {
        },
        error: function() {
        }
    });
    var jsonP_ = xmlhttp.algorithInfo;
    jsonP_ = eval("("+jsonP_+")");
    if(jsonP_==0){
        layer.msg("请选择文件！");
    }else{
        var url =window.location.search;
        if (url.indexOf("?") != -1) {
            var str = url.substr(1)
            strs = str.split("&");
            var id = strs[0].split("=")[1];
        }
        $("#jsonInfo").attr("aid",id);
        $("#jsonInfo").attr("aName",jsonP_.name);
        $("#jsonInfo").attr("aversion",jsonP_.version);
        $("#jsonInfo").attr("atype",jsonP_.algorithmType);
        $("#jsonInfo").attr("afunction",jsonP_.algorithmFunction);
        $("#jsonInfo").attr("acompanyName",jsonP_.companyName);
        $("#jsonInfo").attr("aintroduction",jsonP_.introduction);
        $("#jsonInfo").attr("apostfix",jsonP_.postfix);
        $("#jsonInfo").attr("aplatform",jsonP_.platform);
        $("#jsonInfo").attr("acontainGpu",jsonP_.isContainGpu);
        $("#jsonInfo").attr("auseMpi",jsonP_.isUseMpi);
        $("#jsonInfo").attr("acpuNum",jsonP_.cpuNum);
        $("#jsonInfo").attr("aisLeft",jsonP_.isLeft);
        $("#jsonInfo").attr("ainputCount",jsonP_.inputCount.length);
        $("#jsonInfo").attr("aoutputCount",jsonP_.outputCount.length);
        $("#jsonInfo").attr("aparamsCount",jsonP_.paramsCount.length);
        for(var i =0;i<jsonP_.inputCount.length;i++){
            $("#jsonInfo").attr("inputName"+i,jsonP_.inputCount[i].inputName);
            $("#jsonInfo").attr("inputType"+i,jsonP_.inputCount[i].type);
            $("#jsonInfo").attr("inputIntroduction"+i,jsonP_.inputCount[i].inputIntroduction);
            $("#jsonInfo").attr("inputSuffix"+i,jsonP_.inputCount[i].suffix);
        }
        for(var i =0;i<jsonP_.outputCount.length;i++){
            $("#jsonInfo").attr("outputName"+i,jsonP_.outputCount[i].outputName);
            $("#jsonInfo").attr("outputType"+i,jsonP_.outputCount[i].type);
            $("#jsonInfo").attr("outputIntroduction"+i,jsonP_.outputCount[i].outputIntroduction);
            $("#jsonInfo").attr("outputSuffix"+i,jsonP_.outputCount[i].suffix);
        }
        for(var i =0;i<jsonP_.paramsCount.length;i++){
            $("#jsonInfo").attr("paramSymbol"+i,jsonP_.paramsCount[i].paramSymbol);
            $("#jsonInfo").attr("paramType"+i,jsonP_.paramsCount[i].paramType);
            $("#jsonInfo").attr("paramIntroduction"+i,jsonP_.paramsCount[i].paramIntroduction);
            $("#jsonInfo").attr("paramDefaultValue"+i,jsonP_.paramsCount[i].paramDefaultValue);

        }

        layer.ready(function() {
            //官网欢迎页
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                title: '算法详情预览',
                fix: false,
                scrollbar: false,
                shadeClose: true,
                maxmin: true,
                area: ['1080px', '600px'],
                content: constUrl + 'views/algorithm/xmlUpdateCheck.action'
            });
        });
    }

}
function closeLayer() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
//关闭layer页面功能`
$("#closeLayer").click(function () {
    var index =parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
});